package com.yunfeisoft.business.service.impl;

import com.applet.base.BaseServiceImpl;
import com.applet.sql.separation.DataSourceChange;
import com.applet.utils.Page;
import com.yunfeisoft.business.dao.inter.OmsCompanyAddressDao;
import com.yunfeisoft.business.model.OmsCompanyAddress;
import com.yunfeisoft.business.service.inter.OmsCompanyAddressService;
import com.yunfeisoft.enumeration.YesNoEnum;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * ClassName: OmsCompanyAddressServiceImpl
 * Description: 公司收发货地址表service实现
 * Author: Jackie liu
 * Date: 2020-06-02
 */
@Service("omsCompanyAddressService")
public class OmsCompanyAddressServiceImpl extends BaseServiceImpl<OmsCompanyAddress, String, OmsCompanyAddressDao> implements OmsCompanyAddressService {

    @Override
    @DataSourceChange(slave = true)
    public Page<OmsCompanyAddress> queryPage(Map<String, Object> params) {
        return getDao().queryPage(params);
    }

    @Override
    public int modifySendStatus(String id, int sendStatus) {
        if (sendStatus == YesNoEnum.YES_ACCPET.getValue()) {
            getDao().updateSendStatus(null, YesNoEnum.NO_CANCEL.getValue());
        }
        return getDao().updateSendStatus(id, sendStatus);
    }

    @Override
    public int modifyReceiveStatus(String id, int receiveStatus) {
        if (receiveStatus == YesNoEnum.YES_ACCPET.getValue()) {
            getDao().updateReceiveStatus(null, YesNoEnum.NO_CANCEL.getValue());
        }
        return getDao().updateReceiveStatus(id, receiveStatus);
    }

    @Override
    public int save(OmsCompanyAddress omsCompanyAddress) {
        if (omsCompanyAddress.getSendStatus() == YesNoEnum.YES_ACCPET.getValue()) {
            getDao().updateSendStatus(null, YesNoEnum.NO_CANCEL.getValue());
        }
        if (omsCompanyAddress.getReceiveStatus() == YesNoEnum.YES_ACCPET.getValue()) {
            getDao().updateReceiveStatus(null, YesNoEnum.NO_CANCEL.getValue());
        }
        return super.save(omsCompanyAddress);
    }

    @Override
    public int modify(OmsCompanyAddress omsCompanyAddress) {
        if (omsCompanyAddress.getSendStatus() == YesNoEnum.YES_ACCPET.getValue()) {
            getDao().updateSendStatus(null, YesNoEnum.NO_CANCEL.getValue());
        }
        if (omsCompanyAddress.getReceiveStatus() == YesNoEnum.YES_ACCPET.getValue()) {
            getDao().updateReceiveStatus(null, YesNoEnum.NO_CANCEL.getValue());
        }
        return super.modify(omsCompanyAddress);
    }
}